package android.medicalcloud.com.yiapp.yilian.utils.glide;

import android.content.Context;
import android.medicalcloud.com.yiapp.R;
import android.medicalcloud.com.yiapp.yilian.configer.contance.Constance;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.stream.HttpUrlGlideUrlLoader;
import com.bumptech.glide.module.GlideModule;
import com.bumptech.glide.request.target.ViewTarget;


import java.io.InputStream;


/**
 * Created by yanbo on 16-11-26.
 */
public class CustomerGlideModule implements GlideModule {
    private final static int DISC_SIZE = 256 * 1024 * 1024;

    @Override
    public void registerComponents(Context context, Glide glide) {
        glide.register(GlideUrl.class, InputStream.class, new HttpUrlGlideUrlLoader.Factory());
    }

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {

        ViewTarget.setTagId(R.id.image_tag);
        builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);

        builder.setDiskCache(new DiskLruCacheFactory(Constance.CACHE_IMAGE, DISC_SIZE));
    }

}
